package com.chao.socket.tcp.a;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

public class TcpClient {

    public static void main(String[] args) {
        Socket socket = null;
        OutputStream os = null;

        try {
            // 服务端的ip和端口
            InetAddress address = InetAddress.getByName("localhost");
            socket = new Socket(address, 8090);
            // 获取输入流，写出要发送的数据
            os = socket.getOutputStream();
            os.write("客户端请求连接".getBytes());
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                if (os != null) {
                    os.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

            try {
                if (socket != null) {
                    socket.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
